package com.doublefish.doublefishrobot.ui.home;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.doublefish.doublefishrobot.BuildConfig;
import com.doublefish.doublefishrobot.R;
import com.doublefish.doublefishrobot.base.BaseActivity;
import com.doublefish.doublefishrobot.utils.ToastUtil;
import com.doublefish.doublefishrobot.utils.ble.bean.ModeConstant;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 作者:dugaofeng on 2024/12/17 09:12
 */
public class DevicesBindActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView titleTV;

    @BindView(R.id.ll_s6)
    LinearLayout s6LinearLayout;

//    @BindView(R.id.ll_s3)
//    LinearLayout s3LinearLayout;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_device_bind;
    }

    @Override
    protected void initView() {
        titleTV.setText(R.string.device_type);

        if (BuildConfig.DEBUG) {
            s6LinearLayout.setVisibility(View.VISIBLE);
        }
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {

    }

    @OnClick({R.id.ll_s8, R.id.ll_s6, R.id.ll_s5, R.id.ll_s3})
    public void onDevicesItemClick(View view) {
        switch (view.getId()) {
            case R.id.ll_s8: {
                toBindBleDeviceActivity(ModeConstant.ProtocolTypeS8);
            }
            break;

            case R.id.ll_s6: {
                toBindBleDeviceActivity(ModeConstant.ProtocolTypeS6);
            }
            break;

            case R.id.ll_s5: {
                toBindWifiDeviceActivity(ModeConstant.DeviceTypeS5);
            }
            break;

            case R.id.ll_s3: {
                toBindWifiDeviceActivity(ModeConstant.DeviceTypeS3);
            }
            break;
        }
    }

    private void toBindBleDeviceActivity(int protocolType) {
        boolean granted = checkBlePermission();
        if (granted) {
            Intent intent = DevicesBindBleActivity.makeIntent(this, protocolType);
            startActivity(intent);
        } else {
            ToastUtil.showToast(this, getString(R.string.require_ble_location));
        }
    }

    private void toBindWifiDeviceActivity(int deviceType) {
        boolean granted = checkWIFIPermission();
        if (granted) {
//            Intent intent = new Intent(this, DevicesBindWifiActivity.class);
//            startActivity(intent);

            Intent intent = DevicesBindWifiActivity.makeIntent(this, deviceType);
            startActivity(intent);
        } else {
            ToastUtil.showToast(this, getString(R.string.require_wifi_location));
        }
    }

    @OnClick(R.id.ll_back)
    public void onBackClick() {
        finish();
    }
}
